#include "include/low_power.h"
#include "include/lp_report.h"
#include "service/include/swei_location.h"
#include "service/include/swei_login.h"
#include "service/include/swei_config.h"
#include "service/include/swei_alarm.h"
#include "service/include/swei_cache.h"
#include "service/include/swei_active.h"
#include "service/include/swei_uplink.h"
#include "misc/misc_system.h"
#include "bsp.h"

#include "global.h"
#define LOG_TAG TAG_LP
#include "elog.h"

/**
 * @brief 休眠使能检测
 * @return 0 - 不能休眠, TASK_ALWAYS_SLEEP - 一直休眠, 其他数值: 可休眠的时间, unit: ms
 */
uint32_t report_canstop(void)
{
    /* 配置没有上报成功, 则不允许休眠 */
    if (!swei_config_report_finish())
        return 0;

    /* 报文产生/发送不空闲, 则不允许休眠 */
    if (!swei_uplink_data_idle_get())
        return 0;

    return swei_uplink_data_next_stime_get();
}

/**
 * @brief 休眠前处理函数
 */
void report_prestop(void)
{
}

/**
 * @brief 休眠唤醒后处理函数
 */
void report_poststop(void)
{
}

// 依赖工作模式和激活状态进行配置
sleep_item_t lp_report = {
    .name       = "REPORT",
    .canstop    = report_canstop,
    .prestop    = report_prestop,
    .poststop   = report_poststop,
};

